import json
import traceback
from project.social_security import repeat_write
from gevent import monkey
import time
from flask import Flask, jsonify
# from gevent import pywsgi
from gevent.pywsgi import WSGIServer
# 导入genvent猴子补丁， 实现并发操作
from concurrent.futures import ThreadPoolExecutor
# 下三行代码提供了网络服务多线程
monkey.patch_all()
app = Flask(__name__)


def accept(message):
    try:
        t = repeat_write.write_excel(message)
        return t
    except Exception as e:
        return jsonify({"error":e})


@app.route('/social_security/<message>')
def avs_info(message):
    taske = executor.submit(accept, message)
    y = taske.result()
    return y
    # json数据直接返回
    # return y

    # 非json数据转换使用
    # return jsonify(y)

